home *** CD-ROM | disk | FTP | other *** search
- /*
- * Winaux initialization module
- *
- * Written by Bill Hall
- * 3665 Benton Street, #66
- * Santa Clara, CA 95051
- *
- */
-
- #define NOCOMM
- #include <stdlib.h>
- #include <windows.h>
- #include <ttycls.h>
- #include "winaux.h"
-
- /* local function declarations */
- static BOOL NEAR RegisterWindowClass(HANDLE);
- static void NEAR getcrect(HANDLE hInstance);
- static BOOL NEAR MakeAndShowMainWnd(HANDLE, int);
-
- /* initial window size rectangle */
- static RECT crect;
-
- /* enter here to initialize the program */
- BOOL FAR InitProgram(hInstance,hPrevInstance, lpszCmdLine, cmdShow)
- HANDLE hInstance, hPrevInstance;
- LPSTR lpszCmdLine;
- int cmdShow;
- {
-
- /* if first instance, do these things */
- if (hPrevInstance == NULL) {
- LoadString(hInstance,IDS_ICONSTRING,(LPSTR)szIconTitle,
- sizeof(szIconTitle));
- LoadString(hInstance,IDS_HWND,(LPSTR)szhWnd,sizeof(szhWnd));
- if (!RegisterWindowClass(hInstance))
- return FALSE;
- }
- else
- return FALSE;
- /* no additional instances allowed */
-
- /* read the rectangle for create window */
- getcrect(hInstance);
-
- /* create the window */
- if (!MakeAndShowMainWnd(hInstance,cmdShow))
- return FALSE;
-
- /* write the handle to win.ini */
- if (!SetWinIni(MWnd.hWnd))
- return FALSE;
-
- /* show success */
- return TRUE;
- }
-
- /* register the windows class */
- static BOOL near RegisterWindowClass(hInstance)
- HANDLE hInstance;
- {
-
- PWNDCLASS pWndClass;
- HANDLE hTemp;
-
- /* get the application name from the resources */
- LoadString(hInstance,IDS_APPNAME,(LPSTR)szAppName,sizeof(szAppName));
-
- /* make space for the WNDCLASS structure in the heap */
- hTemp = LocalAlloc(LPTR,sizeof(WNDCLASS));
- pWndClass = (PWNDCLASS)LocalLock(hTemp);
-
- /* enter data */
- pWndClass->hCursor = LoadCursor(NULL, IDC_ARROW); /* stock cursor */
- pWndClass->hIcon = NULL; /* no icon */
- pWndClass->lpszMenuName = (LPSTR)szAppName; /* this menu */
- pWndClass->lpszClassName = (LPSTR)szAppName; /* class name */
- pWndClass->hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); /* background */
- pWndClass->hInstance = hInstance; /* instance */
- pWndClass->style = CS_VREDRAW | CS_HREDRAW; /* style */
- pWndClass->lpfnWndProc = MainWndProc; /* pointer to wind proc */
- pWndClass->cbWndExtra = sizeof(PTTYWND); /* space for ptr to MWnd */
-
- /* if failure, return FALSE */
- if (!RegisterClass((LPWNDCLASS)pWndClass))
- return FALSE;
-
- /* success, so free up heap data and show ok */
- LocalUnlock(hTemp);
- LocalFree(hTemp);
- return TRUE;
- }
-
- /* get the user's window size or load and write default values */
- static void NEAR getcrect(HANDLE hInstance)
- {
-
- char buf[20];
- char keystr[20];
- short temp;
-
- LoadString(hInstance,IDS_X,(LPSTR)keystr,sizeof(keystr));
- temp = GetProfileInt((LPSTR)szAppName, (LPSTR)keystr, -1);
- if (temp <= 0) {
- crect.left = CW_USEDEFAULT;
- if (temp < 0)
- WriteProfileString((LPSTR)szAppName, (LPSTR)keystr,
- (LPSTR)itoa(crect.left, buf, 10));
- }
- else
- crect.left = temp;
-
- LoadString(hInstance,IDS_Y,(LPSTR)keystr,sizeof(keystr));
- temp = GetProfileInt((LPSTR)szAppName, (LPSTR)keystr, -1);
- if (temp <= 0) {
- crect.top = 0;
- if (temp < 0)
- WriteProfileString((LPSTR)szAppName, (LPSTR)keystr,
- (LPSTR)itoa(crect.top, buf, 10));
- }
- else
- crect.top = temp;
-
- LoadString(hInstance,IDS_CX,(LPSTR)keystr,sizeof(keystr));
- temp = GetProfileInt((LPSTR)szAppName, (LPSTR)keystr, -1);
- if (temp <= 0) {
- crect.right = CW_USEDEFAULT;
- if (temp < 0)
- WriteProfileString((LPSTR)szAppName, (LPSTR)keystr,
- (LPSTR)itoa(crect.right, buf, 10));
- }
- else
- crect.right = temp;
-
- LoadString(hInstance,IDS_CY,(LPSTR)keystr,sizeof(keystr));
- temp = GetProfileInt((LPSTR)szAppName, (LPSTR)keystr, -1);
- if (temp <= 0) {
- crect.bottom = 0;
- if (temp < 0)
- WriteProfileString((LPSTR)szAppName, (LPSTR)keystr,
- (LPSTR)itoa(crect.bottom, buf, 10));
- }
- else
- crect.bottom = temp;
-
- }
-
- /* create a window of the class registered above */
- static BOOL NEAR MakeAndShowMainWnd(hInstance, cmdShow)
- HANDLE hInstance;
- int cmdShow;
- {
-
- char szWinTitle[30];
-
- /* get the text for the title */
- LoadString(hInstance, IDS_WINTITLE, (LPSTR)szWinTitle,sizeof(szWinTitle));
-
- /* create the window */
- MWnd.hWnd = CreateWindow((LPSTR)szAppName, /* class */
- (LPSTR)szWinTitle, /* title string */
- WS_OVERLAPPEDWINDOW, /* style */
- crect.left, /* values obtained from getcrect */
- crect.top,
- crect.right,
- crect.bottom,
- (HWND)NULL, /* no parent */
- (HMENU)NULL, /* class menu */
- (HANDLE)hInstance, /* instance */
- (LPSTR)&MWnd); /* ptr to window structure */
-
- /* if successful, display the window */
- if (MWnd.hWnd && MWnd.hVidBuf) {
- ShowWindow(MWnd.hWnd, cmdShow);
- UpdateWindow(MWnd.hWnd);
- return TRUE;
- }
- /* return failure */
- return FALSE;
- }
-
- /* this routine is called upon receipt of the WM_CREATE message */
- void WndCreate(hWnd, lParam)
- HWND hWnd;
- LONG lParam;
- {
-
- HDC hDC;
- TEXTMETRIC TM;
- short width, height, cwidth, cheight;
- LPCREATESTRUCT pCS;
- PTTYWND pMWnd;
-
- /* we are going to create a buffer for a window this large */
- width = GetSystemMetrics(SM_CXFULLSCREEN);
- height = GetSystemMetrics(SM_CYFULLSCREEN);
-
- /* get the font size */
- hDC = GetDC(hWnd);
- GetTextMetrics(hDC, &TM);
- cwidth = TM.tmAveCharWidth;
- cheight = TM.tmHeight + TM.tmExternalLeading;
- ReleaseDC(hWnd, hDC);
-
- /* here we retrieve the pointer to our local window stucture */
- pCS = (LPCREATESTRUCT)lParam;
- pMWnd = (PTTYWND)LOWORD(pCS->lpCreateParams);
-
- /* initialize the extra data to the pointer to the TWnd structure */
- SetWindowWord(hWnd,0,(WORD)pMWnd);
-
- /* now create the text buffer and set some defaults */
- InitTTYWindow(pMWnd,0,0,width,height,cwidth,cheight,FALSE,TRUE,TRUE,0x7f);
- }